//get方式提交数据
const express = require('express');
const app = express();
app.listen(3000,()=>{
  console.log('服务器已启动');
});
const path = require('path');
app.get('/index',(req,res)=>{
  res.sendFile(path.join(__dirname,'./view/index.html'));
})
app.get('/getData',(req,res)=>{
  //get传递参数(数据)都会以对象形式保存在(req.query)属性中
  console.log(req.query)
  //之前是使用url模块中的query属性
  res.end('ok')
});

// /getparams/aaa/bbb
// /getparams/:a/:b -- req.params = {a:'aaa',b:'bbb'},
// /getparams/aaa/:b -- req.params = {b:'bbb'}
// /getparams/aaa/bbb -- req.params = {}
// app.get('/getparams/:a/:b',(req,res)=>{
//   console.log(req.params)
//   res.end('okok');
// });
// /getparams/aaa/bbb
// /getparams/aaa/:str -- {str:'aaa'}
app.get('/getparams/:str/bbb',(req,res)=>{
  console.log(req.params);//{str:'aaa'}
  res.end('oook');
});

//使用 req.params时，url地址和参数是由get方法的 参数1 来决定的
// /getparams/aaa/bbb/ccc

//参数1: /getparams/:a/:b/:c  url= /getparams  req.params = {a:'aaa',b:'bbb';c:'ccc'}
//参数1: /getparams/aaa/bbb/:c url = /getparams/aaa/bbb  req.params = {c:'ccc'}
//参数1: /getparams/aaa/bbb/ccc url = /getparams/aaa/bbb/ccc  req.params = {}